package com.example.wm.SanWar.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.example.wm.SanWar.VO.CommunicationEntityVO;
import com.example.wm.SanWar.entity.CommunicationEntity;
import com.example.wm.SanWar.mapper.CommunicationMapper;
import com.example.wm.SanWar.service.CommunicationService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.List;

@Service
public class CommunicationImpl extends ServiceImpl<CommunicationMapper, CommunicationEntity> implements CommunicationService {

    @Resource
    private CommunicationMapper communicationMapper;

    public List<CommunicationEntity> getCategoryTree(CommunicationEntity communicationEntity) {
        LambdaQueryWrapper<CommunicationEntity> lq=new LambdaQueryWrapper<>();
        lq.eq(CommunicationEntity::getParentsid, communicationEntity.getId());
        List<CommunicationEntity> rootCategories = communicationMapper.selectList(lq);
//        for (CommunicationEntity root : rootCategories) {
//            buildTree(root);
//        }
        return rootCategories;
    }

        private void buildTree(CommunicationEntity parent) {
            LambdaQueryWrapper<CommunicationEntity> lq=new LambdaQueryWrapper<>();
            lq.eq(CommunicationEntity::getParentsid,parent);

            List<CommunicationEntity> children = communicationMapper.selectList(lq);
//            parent.setChildren(children);
            for (CommunicationEntity child : children) {
                buildTree(child);
            }
        }



}
